<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script type="text/javascript" src="http://lostbase.local/js/lsjs/lsjs.js"></script>
</head>
<body>
<div id="resps"></div>
<textarea id="text"></textarea><button onclick="connect()">Connect</button><button onclick="message()">Do It</button>
<script type="text/javascript">

    var id = "";

    function onResponse(status, xhr, param) {

        if(status == 'complete') {
            document.getElementById('resps').innerHTML += xhr.responseText + "<hr/>";

            lsjs.transport.asyncRequest("/main", 'POST', id + "\nwait\n" + ' ', onResponse);

        }
    }

    function onConnect(status, xhr, param) {

        if(status == 'complete') {
            document.getElementById('resps').innerHTML += xhr.responseText + "<hr/>";
            var parts = xhr.responseText.split('\n');
            if(parts[2] == "OK") {
                id = parts[0];
            }


            lsjs.transport.asyncRequest("/main", 'POST', id + "\nwait\n" + ' ', onResponse);

        }
    }

    function message() {

        if(id) {
            lsjs.transport.abort();
            lsjs.transport.asyncRequest("/main", 'POST', id + "\nmessage\n" + ' ' + document.getElementById('text').value, onResponse);
        }

    }

    function connect() {

        lsjs.transport.abort();
        lsjs.transport.asyncRequest("/main", 'POST', "connect\n\n", onConnect);


    }

</script>
</body>
</html>